package com.github.linkoog.model_designer.ide.editer.common;

import javax.swing.*;
import java.awt.*;

public class DbTypeComboBoxCellRender implements ListCellRenderer {

    private JLabel label;


    public DbTypeComboBoxCellRender() {
        label = new JLabel();
        label.setOpaque(true);
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (value == null) {
            label.setText("");
            return label;
        }

        if (value instanceof DbType){
            DbType dbType = (DbType)value;
            label.setIcon(dbType.getIcon());
            label.setText(dbType.getName());
        } else if (value instanceof CharSequence){
            label.setText(value.toString());
        }

        return label;
    }
}
